

import 'package:get/get.dart';
import 'package:zfth/api/ReportApi.dart';
import 'package:zfth/pages/home/homecount/HomeCountState.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import '../../../api/AlarmApi.dart';
import '../../../utils/Settings.dart';
import '../../../utils/eventbus/EventBus.dart';
import '../../../utils/eventbus/EventBusMethod.dart';


class HomeCountLogic extends GetxController{

  final state = HomeCountState();

  @override
  void onInit() {
    queryEqAndAlarmCount();

    bus.on(EventBusMethod.methods["wbSocket事件"], (arg) {
      if(arg["type"] == Settings.websocketDataType["设备和报警数量统计"]){
        state.count = arg["data"];
        update();
      }
    });
  }



  @override
  void onClose() {
    bus.off(EventBusMethod.methods["wbSocket事件"]);
  }

  void queryEqAndAlarmCount() async{
    dynamic res =  await ReportApi.eqAndAlarmCount();
    if(res["success"]){
      state.count = res["result"];
      update();
    }else{
      EasyLoading.showError("设备和报警数据查询失败");
    }
  }
}


